<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const check = (arr, limit, m, k) => {
      let c = 0, flower = 0
      for (let a of arr) {
        if (a <= limit) {
          flower++
          if (flower == k) {
            c++
            flower = 0
          }
        } else flower = 0
      }
      return c >= m
    }

    var minDays = function (bloomDay, m, k) {
      if (bloomDay.length < m * k) return -1
      let left = Math.min(...bloomDay), right = Math.max(...bloomDay)
      while (left <= right) {
        const mid = left + Math.floor((right - left) / 2)
        if (check(bloomDay, mid, m, k)) {
          right = mid - 1
        } else left = mid + 1
      }
      return left
    };
    console.log(minDays([1, 10, 3, 10, 2], 3, 1));
  </script>
</body>

</html>